//
//  WHNoDataViewTool.m
//  BinFengExpressOwner
//
//  Created by 邓伟浩 on 2018/10/29.
//  Copyright © 2018年 BinFeng. All rights reserved.
//

#import "WHNoDataViewTool.h"

@implementation WHNoDataViewTool

+ (UIView *)addNodataViewAt:(UIView *)superView imageName:(NSString *)imageName topOffset:(double)height tipsLabelText:(NSString *)tipsText tapAction:(void (^)(id sender))block {
    UIView *contentView = [[UIView alloc] init];
    [superView addSubview:contentView];
    [contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(superView);
    }];
    
    UIImageView *imageView = [[UIImageView alloc] init];
    [contentView addSubview:imageView];
    imageView.image = IMAGE_NAMED(imageName);
    [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.mas_equalTo(kRealwidth(125));
        make.top.mas_equalTo(contentView.mas_top).offset(height);
        make.centerX.mas_equalTo(contentView.mas_centerX);
    }];
    
    imageView.userInteractionEnabled = YES;
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithActionBlock:^(id  _Nonnull sender) {
        if (block) {
            block(sender);
        }
    }];
    [imageView addGestureRecognizer:tap];
    
    UILabel *tipsLabel = [[UILabel alloc] init];
    [contentView addSubview:tipsLabel];
    tipsLabel.textAlignment = NSTextAlignmentCenter;
    tipsLabel.textColor = HexColor(@"999999");
    tipsLabel.text = tipsText;
    
    [tipsLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(kRealwidth(15));
        make.top.mas_equalTo(imageView.mas_bottom).offset(kRealwidth(20));
        make.centerX.mas_equalTo(contentView.mas_centerX);
    }];
    
    return contentView;
    
    //    return [self addNodataViewAt:superView imageName:imageName tipsLabelText:tipsText tapAction:block];
}

+ (UIView *)addNodataViewAt:(UIView *)superView imageName:(NSString *)imageName tipsLabelText:(NSString *)tipsText tapAction:(void (^)(id sender))block {
    return [self addNodataViewAt:superView imageName:imageName topOffset:kRealwidth(125) tipsLabelText:tipsText tapAction:block];
}

@end
